package cn.bdqn.service.Impl;

import cn.bdqn.dao.Ebook_entryMapper;
import cn.bdqn.pojo.Ebook_entry;
import cn.bdqn.service.Ebook_entryService;
import cn.bdqn.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("ebook_entryService")
public class Ebook_entryServiceImpl implements Ebook_entryService {

    @Autowired
    @Qualifier("ebook_entryMapper")
    private Ebook_entryMapper ebook_entryMapper;

    public void setEntryMapper(Ebook_entryMapper entryMapper) {
        this.ebook_entryMapper = entryMapper;
    }

    @Override
    public List<Ebook_entry> getUserList(Integer categoryId, Integer pageNo) {
        if(pageNo==null){
            pageNo=1;
        }
        int beginIndex=(pageNo-1)* Constants.pageSize;
        List<Ebook_entry> list=ebook_entryMapper.getUserList(categoryId,beginIndex,Constants.pageSize);
        return list;
    }

    @Override
    public int getcount(Integer categoryId) {
        return ebook_entryMapper.getcount(categoryId);
    }

    @Override
    public int getPages(Integer categoryId) {
        int count=ebook_entryMapper.getcount(categoryId);
        return count%Constants.pageSize==0?count/Constants.pageSize:count/Constants.pageSize+1;
    }

    @Override
    public int addEntry(Ebook_entry ebook_entry) {
        return ebook_entryMapper.addEntry(ebook_entry);
    }

    @Override
    public Ebook_entry getEntryById(Integer id) {
        return ebook_entryMapper.getEntryById(id);
    }

    @Override
    public int update(Ebook_entry ebook_entry) {
        return ebook_entryMapper.update(ebook_entry);
    }

    @Override
    public int del(Integer id) {
        return ebook_entryMapper.del(id);
    }
}
